#include "chatserver.hpp"
#include"chatservice.hpp"
#include <iostream>
#include <signal.h>
using namespace std;
//服务器ctrl+c后，重置User的state
void resetHandler(int){
    ChatService::instance()->reset();
    exit(0);
}
int main(int argc,char** argv)
{
    try
    {
        if(argc!=3){
            cerr<<"command invalid! example ./ChatServer 127.0.0.1 6000"<<endl;
            exit(-1);
        }
        char* ip = argv[1];
        uint16_t port = atoi(argv[2]);
        signal(SIGINT, resetHandler);
        EventLoop loop;
        InetAddress addr(ip, port);
        ChatServer server(&loop, addr, "ChatServer");
        server.start();
        loop.loop();
        return 0;
    }
    catch (std::exception &e)
    {
        cerr << e.what() << endl;
    }
}